package com.gnerv.sylvanas.business.manage.operation;

import com.gnerv.sylvanas.framework.core.BaseCurrentAccount;
import com.gnerv.sylvanas.business.manage.model.bo.ViewBO;
import com.gnerv.sylvanas.business.manage.model.dto.ViewDTO;
import com.gnerv.sylvanas.business.manage.model.dto.ViewTreeDTO;
import com.gnerv.sylvanas.business.manage.model.entity.View;
import com.gnerv.sylvanas.business.manage.storage.ViewStorageService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;

/**
 * @author Gnerv LiGen
 */
@Slf4j
@Service
@AllArgsConstructor
public class ViewOperationService {

    private final BaseCurrentAccount baseCurrentAccount;
    private final ViewStorageService viewStorageService;

    
    public boolean create(ViewBO viewBO) {
        View view = viewBO.toView();
        
        viewStorageService.insert(view);
        return true;
    }

    
    public boolean deleteByUkId(String ukId) {
        viewStorageService.deleteByUkId(ukId);
        return true;
    }

    
    public boolean updateByUkId(ViewBO viewBO) {
        View view = viewBO.toView();
        view.setGmtModified();
        viewStorageService.updateByUkId(view);
        return true;
    }

    
    public ViewDTO selectByUkId(String ukId) {
        return viewStorageService.selectByUkId(ukId);
    }

    
    public List<ViewDTO> selectListByName(String name) {
        return viewStorageService.selectListByName(name);
    }

    
    public List<ViewDTO> selectListByParentUkId(String parentUkId) {
        return viewStorageService.selectListByParentUkId(parentUkId);
    }

    
    public List<ViewTreeDTO> selectListTreeByParentUkId(String parentUkId) {
        return viewStorageService.selectListTreeByParentUkId(parentUkId);
    }

    
    public List<ViewTreeDTO> selectListTreeByAccountUkId(String accountUkId) {
        return viewStorageService.selectListTreeByParentUkIdAndAccountUkId("0", accountUkId);
    }

    
    public boolean bindRole(String viewUkId, Set<String> roleUkIdList) {
        viewStorageService.bindRole(viewUkId, roleUkIdList, baseCurrentAccount.ukId());
        return true;
    }

    
    public boolean unbindRole(String viewUkId) {
        viewStorageService.unbindRole(viewUkId);
        return true;
    }

    
    public boolean bindRoute(String viewUkId, String routeUkId) {
        viewStorageService.bindRoute(viewUkId, routeUkId, baseCurrentAccount.ukId());
        return true;
    }

    
    public boolean unbindRoute(String viewUkId) {
        viewStorageService.unbindRoute(viewUkId);
        return true;
    }
}




